#include <iostream>
#include <vector>

class MemoryPool {
private:
    std::vector<char*> memoryBlocks;
    std::vector<bool> isBlockAllocated;
    size_t blockSize;
    size_t numBlocks;

public:
    MemoryPool(size_t blockSize, size_t numBlocks) : blockSize(blockSize), numBlocks(numBlocks) {
        memoryBlocks.resize(numBlocks);
        isBlockAllocated.resize(numBlocks, false);

        for (size_t i = 0; i < numBlocks; i++) {
            memoryBlocks[i] = new char[blockSize];
        }
    }

    ~MemoryPool() {
        for (size_t i = 0; i < numBlocks; i++) {
            delete[] memoryBlocks[i];
        }
    }

    void* allocate() {
        for (size_t i = 0; i < numBlocks; i++) {
            if (!isBlockAllocated[i]) {
                isBlockAllocated[i] = true;
                return memoryBlocks[i];
            }
        }
        return nullptr;
    }

    void deallocate(void* block) {
        for (size_t i = 0; i < numBlocks; i++) {
            if (memoryBlocks[i] == block) {
                isBlockAllocated[i] = false;
                break;
            }
        }
    }
};

int main() {
    // Example usage
    MemoryPool pool(sizeof(int), 10);

    int* ptr1 = static_cast<int*>(pool.allocate());
    *ptr1 = 42;

    int* ptr2 = static_cast<int*>(pool.allocate());
    *ptr2 = 99;

    std::cout << *ptr1 << std::endl;  // Output: 42
    std::cout << *ptr2 << std::endl;  // Output: 99

    pool.deallocate(ptr1);
    pool.deallocate(ptr2);

    return 0;
}
